#include <stdio.h>
#include <stdlib.h>
#include<string.h> 
struct Student {
    char name[50];
    int score;
    struct Student *next;
};

struct ClassList {
    struct Student *head;
    int score;
    int count;
};

void addStudent(struct ClassList *list, char name[], int score) {
    struct Student *newStudent = (struct Student *)malloc(sizeof(struct Student));
    if (newStudent == NULL) {
        return;
    }
    strcpy(newStudent->name, name);
    newStudent->score = score;
    newStudent->next = NULL;

    if (list->head == NULL) {
        list->head = newStudent;
    } else {
        struct Student *current = list->head;
        while (current->next != NULL) {
            current = current->next;
        }
        current->next = newStudent;
    }
    list->count++;
}

void getAverageAndMax(struct ClassList *list, float *average, char maxName[], int *maxScore) {
    struct Student *current = list->head;
    int totalScore = 0;
    *maxScore = -1;
    while (current != NULL) {
        totalScore += current->score;
        if (current->score > *maxScore) {
            strcpy(maxName, current->name);
            *maxScore = current->score;
        }
        current = current->next;
    }
    *average = (float)totalScore / list->count;
}

int main() {
    int m;
    scanf("%d", &m);

    struct ClassList classes[m];
    for (int i = 0; i < m; i++) {
        int n;
        scanf("%d", &n);
        classes[i].head = NULL;
        classes[i].count = 0;

        for (int j = 0; j < n; j++) {
            char name[50];
            scanf("%s %d", name, &classes[i].score);
            addStudent(&classes[i], name, classes[i].score);
        }
    }

    for (int k = 0; k < m; k++) {
        float average;
        char maxName[50];
        int maxScore;
        getAverageAndMax(&classes[k], &average, maxName, &maxScore);
        printf("%d %.2f %s %d\n", k + 1, average, maxName, maxScore);
    }

    return 0;
}
